package com.ooqiu.gaming.ui.dialog;

import android.content.DialogInterface;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;

import com.ooqiu.gaming.R;
import com.ooqiu.gaming.utils.SettingPrefUtil;
import com.ooqiu.gaming.utils.SizeUtils;

/**
 * @author Eenie
 * @date 2017/12/4
 */

public class IndexTaskDialog extends BaseBottomDialog implements View.OnClickListener {

    private ImageButton mBtnCancel;
    private ImageButton mBtnEnter;

    private View.OnClickListener mOnClickListener;

    @Override
    public int getLayoutRes() {
        return R.layout.custom_dialog_index_alert;
    }

    @Override
    public void bindView(View v) {
        mBtnCancel = v.findViewById(R.id.btn_cancel);
        mBtnEnter = v.findViewById(R.id.btn_enter);
        mBtnCancel.setOnClickListener(this);
        mBtnEnter.setOnClickListener(this);

    }

    @Override
    public void onStart() {
        super.onStart();
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.dimAmount = getDimAmount();
        params.width = WindowManager.LayoutParams.MATCH_PARENT + SizeUtils.dip2px(getContext(), 300);
        if (getHeight() > 0) {
            params.height = getHeight();
        } else {
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        }
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);
        getDialog().setCanceledOnTouchOutside(false);

    }


    @Override
    public boolean getCancelOutside() {
        return false;
    }

    @Override
    public void onClick(View v) {
        getDialog().dismiss();
        if (v == mBtnEnter && mOnClickListener != null) {
            mOnClickListener.onClick(v);
        }
    }




    public void setOnEnterClickListener(View.OnClickListener listener) {
        mOnClickListener = listener;
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        SettingPrefUtil.setIndexAlertTime(getContext(), System.currentTimeMillis());
    }
}
